Fix SonarQube issues: duplicated strings and cognitive complexity#71
Open
devin-ai-integration[bot] wants to merge 2 commits intomainfrom
Open
Fix SonarQube issues: duplicated strings and cognitive complexity#71devin-ai-integration[bot] wants to merge 2 commits intomainfrom
devin-ai-integration[bot] wants to merge 2 commits intomainfrom
Conversation
- Replace hardcoded 'Repository owner' and 'Repository name' strings with existing constants DescriptionRepositoryOwner and DescriptionRepositoryName - Refactor ListDiscussions function to reduce cognitive complexity from 27 to ~10 by extracting helper functions: discussionNodeToIssue, fetchDiscussionsWithCategory, and fetchDiscussionsWithoutCategory Fixes: - go:S1192 (String literals should not be duplicated) - HIGH severity - go:S3776 (Cognitive Complexity should not be too high) - HIGH severity Co-Authored-By: parker.duff@codeium.com <pwjduff@gmail.com>
Author
🤖 Devin AI EngineerI'll be helping with this pull request! Here's what you should know: ✅ I will automatically:
Note: I can only respond to comments from users who have write access to this repository. ⚙️ Control Options:
|
Combine fetchDiscussionsWithCategory and fetchDiscussionsWithoutCategory into a single fetchDiscussions function to reduce code duplication and address SonarCloud duplication check failure. Co-Authored-By: parker.duff@codeium.com <pwjduff@gmail.com>
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.


This PR addresses two HIGH severity SonarQube issues in
pkg/github/discussions.go:Changes
1. Duplicated String Literals (go:S1192)
Replaced hardcoded "Repository owner" and "Repository name" strings with existing constants
DescriptionRepositoryOwnerandDescriptionRepositoryNamefrom actions.go across all discussion-related functions.2. Cognitive Complexity (go:S3776)
Refactored
ListDiscussionsfunction to reduce cognitive complexity from 27 to approximately 10 by extracting:discussionNodetype - shared struct for GraphQL responsediscussionNodeToIssue()- converts a discussion node to a GitHub IssuefetchDiscussions()- consolidated helper that handles both category-filtered and unfiltered queriesUpdates Since Last Revision
fetchDiscussionsWithCategory()andfetchDiscussionsWithoutCategory()into a singlefetchDiscussions()function to reduce code duplicationHuman Review Checklist
discussionNodetype correctly matches the GraphQL response structure for both query variantsfetchDiscussions()helper maintains behavioral equivalence with the original inline codeTradeoffs
fetchDiscussions()have similar structure but cannot be unified due to different GraphQL query signatures (with/without categoryId parameter) - this is a constraint of the githubv4 library's struct tag-based query definition.Alternatives Considered
Link to Devin run: https://app.devin.ai/sessions/0e8426348b5a4cebb73a47f5441f8658
Requested by: parker.duff@codeium.com (@parkerduff)